﻿namespace Pyramid.Hardware
{
    using Pyramid.Hardware.Gates;

    /// <summary>
    /// 
    /// </summary>
    public class FlipFlopBase
    {
        private CycleUpGate qUp;
        private NotGate qPrime;
        private CycleDownGate qDown;
        private OutputLine q;

        protected FlipFlopBase()
        {
            this.q = new OutputLine(Trivalent.Unknown);
        }

        protected void SetOutput(Trivalent signal)
        {
            this.q.SetOutput(signal);
        }

        public virtual ILine Q
        {
            get
            {
                return this.q;
            }
        }

        public ILine QUp
        {
            get
            {
                if (this.qUp == null)
                {
                    this.qUp = new CycleUpGate(this.Q);
                }

                return this.qUp;
            }
        }

        public ILine QPrime
        {
            get
            {
                if (this.qPrime == null)
                {
                    this.qPrime = new NotGate(this.Q);
                }

                return this.qPrime;
            }
        }

        public ILine QDown
        {
            get
            {
                if (this.qDown == null)
                {
                    this.qDown = new CycleDownGate(this.Q);
                }

                return this.qDown;
            }
        }
    }
}
